// FilerFrogUpdater.cpp : Defines the entry point for the application.
//

#include "stdafx.h"
#include "UpdateWindow.h"

int APIENTRY _tWinMain(HINSTANCE hInstance,
					   HINSTANCE hPrevInstance,
					   LPTSTR    lpCmdLine,
					   int       nCmdShow)
{
	wstring args[3];
	wstring cmdLine = GetCommandLine();

	int count = 0;
	int begin = 0;
	int end = 0;
	int total = 0;
	unsigned int i;

	for (i=0; i < cmdLine.length(); i++)
	{        
		if (cmdLine.at(i) == L'"')
		{
			count++;

			if (count == 2)
			{
				count = 0;
			}
		}
		else if (cmdLine.at(i) == L' ' && count == 0)
		{
			if (total > 2)
			{
				break;
			}

			end = i;
			args[total] = cmdLine.substr(begin, end - begin);
			total++;		
			begin = end + 1;			
		}
	}

	if (total < 3)
	{
		end = i;
		args[total] = cmdLine.substr(begin, end - begin);
	}

	if (args[1] == L"/Silent")
	{
		// FrogMessageBox(NULL, L"Silent", L"Silent", 0);
		FilerFrogUpdater m_FilerFrogUpdater;

		if (m_FilerFrogUpdater.CheckInternetConnection())
		{		
			if (m_FilerFrogUpdater.CheckVersion())
			{
				CUpdateWindow updateWindow(true);
				return (int)updateWindow.DoModal(NULL);	
			}
		}

		return 0;
	}
	else
	{
		CUpdateWindow updateWindow;
		return (int)updateWindow.DoModal(NULL);	
	}
}
